package com.ccp.dev.system.controller;

import com.ccp.dev.core.basic.internationalization.SysBaseController;
import com.ccp.dev.core.basic.consts.UrlConstants;
import com.ccp.dev.core.basic.model.SysAuditModelType;
import com.ccp.dev.core.basic.web.query.QueryFilter;
import com.ccp.dev.core.basic.util.UUIDUtils;
import com.ccp.dev.core.util.StringUtil;
import com.ccp.dev.core.util.RequestUtil;
import com.ccp.dev.core.util.log.SysAuditThreadLocalHolder;
import com.ccp.dev.system.model.SysLoginLog;
import com.ccp.dev.system.service.SysLoginLogService;
import com.ccp.dev.core.basic.annotion.Action;
import java.util.Date;
import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.ModelMap;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;

/**
 * 登录日志 信息操作处理控制器
 * 
 * @author zw
 * @date 2019-07-26 16:56:45
 */
@Controller
@Action(ownermodel = SysAuditModelType.LOGIN_MANAGEMENT)
@RequestMapping("/system/sysLoginLog")
public class SysLoginLogController extends SysBaseController{
	@Resource
	private SysLoginLogService sysLoginLogService;

    /**
     * 功能描述: 跳转到首页
     *
     * @return: java.lang.String
     * @auther: zw
     * @date: 2019-07-26 16:56:45
     */
    @RequestMapping(UrlConstants.VIEW_DISPATCH_PREFIX + UrlConstants.MODULE_FUNCTION_LIST)
    @Action(description="登录日志首页页面跳转",exectype = "页面跳转日志")
    public String list() {
        return  "sysLoginLog/list";
    }

    /**
     * 功能描述: 跳转到新增页面
     *
     * @return: java.lang.String
     * @auther: zw
     * @date: 2019-07-26 16:56:45
     */
    @RequestMapping(UrlConstants.VIEW_DISPATCH_PREFIX + UrlConstants.MODULE_FUNCTION_ADD_UPDATE)
    @Action(description="登录日志新增页面跳转",exectype = "页面跳转日志")
    public String add(HttpServletRequest request,ModelMap modelMap) {
        String id = RequestUtil.getString(request,"id");
        modelMap.put("id",id);
        return "sysLoginLog/add";
    }

    /**
     * 功能描述: 根据主键ID删除数据的通用删除方法
     *
     * @param: id 参数名称必须是"id"
     * @return: java.lang.Object
     * @auther: zw
     * @date: 2019-07-26 16:56:45
     */
    @PostMapping(UrlConstants.MODULE_FUNCTION_DELETE)
    @ResponseBody
    @Action(description="根据主键ID删除登录日志数据",
            detail = "<#if showName>删除【账号：${entity.account},时间：${entity.logintime?string('yyyy-MM-dd HH:mm:ss')}】登录日志数据<#else>根据主键删除</#if><#if success>成功<#else>失败</#if>",
            exectype = "删除日志")
    public Object delete(@RequestParam("id") String id) {
        SysAuditThreadLocalHolder.putParamerter("showName", false);
        if (StringUtil.isEmpty(id)) {
            SysAuditThreadLocalHolder.putParamerter("success", false);
            return fail("delete.failure.message");
        }
        SysAuditThreadLocalHolder.putParamerter("showName", true);
        SysAuditThreadLocalHolder.putParamerter("entity", sysLoginLogService.getOneById(id));
        try{
             sysLoginLogService.delByIdArray(id.split(","));
             SysAuditThreadLocalHolder.putParamerter("success", true);
             return getResultDataSuccess("delete.success");
        }catch (Exception e){
            SysAuditThreadLocalHolder.putParamerter("success", false);
            return getResultDataError("delete.failure");
        }
    }
    /**
     * 功能描述: 根据主键id获取一条数据的通用查询方法
     *
     * @param: id 参数对象必须是"id"
     * @return: java.lang.Object
     * @auther: zw
     * @date: 2019-07-26 16:56:45
     */
    @RequestMapping(UrlConstants.MODULE_FUNCTION_GET)
    @ResponseBody
    @Action(description="根据主键id查询登录日志的一条数据",
            detail = "<#if success>根据主键查询【账号：${account}】登录日志成功<#else>根据主键查询登录日志失败</#if>",
            exectype = "查询日志")
    public Object get(@RequestParam("id") String id) {
        SysLoginLog sysLoginLog = sysLoginLogService.getOneById(id);
        if (null == sysLoginLog) {
            SysAuditThreadLocalHolder.putParamerter("success", false);
            return getResultDataError("get.failure");
        }
        SysAuditThreadLocalHolder.putParamerter("success", true);
        SysAuditThreadLocalHolder.putParamerter("account", sysLoginLog.getAccount());
        return getResultDataSuccess("get.success",sysLoginLog);
    }

    /**
     * 功能描述: 附带检索条件的分页查询
     *
     * @param: [request] http请求
     * @return: java.lang.Object
     * @auther: zw
     * @date: 2019-07-26 16:56:45
     */
    @RequestMapping(UrlConstants.MODULE_FUNCTION_LIST)
    @ResponseBody
    @Action(description="附带检索条件的分页查询登录日志",exectype = "查询日志")
    public Object list(HttpServletRequest request) {
        QueryFilter queryFilter = new QueryFilter(request, true);
        //分页数据
        List<SysLoginLog> pageDatas = sysLoginLogService.queryList(queryFilter);
        return success(pageDatas, queryFilter.getPageBean().getTotalCount());
    }
	
}
